/**
 * 
 */
package org.rico.dynamic;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.rico.dynamic.serivce.TaskService;
import org.rico.util.ScheduleJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

/**
 * 任务
 * @author rico
 *
 */
public class QuartzJobFactory implements Job {
	private static final Logger logger = LoggerFactory.getLogger(QuartzJobFactory.class);

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		ScheduleJob scheduleJob = (ScheduleJob)context.getMergedJobDataMap().get("scheduleJob");
		logger.info("###Task[{}] execute...", scheduleJob.getJobName());

//        TaskService taskService = (TaskService) context.getMergedJobDataMap().get("taskService");
//        taskService.hello(scheduleJob.getJobName());
        
        ApplicationContext applicationContext = (ApplicationContext) context.getMergedJobDataMap().get("applicationContext");
        if(applicationContext != null) {
        	 TaskService taskService = (TaskService) applicationContext.getBean("taskService");
             taskService.hello(scheduleJob.getJobName());
        }
	}

}
